<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
                <tr><td><?= translate('AREA_ID') ?>:</td><td><input type="text" name="row[id]" id="id" size="25" value="<?= $lastarea ? $lastarea['idarr'][0] . ":" . ($lastarea['idarr'][1] + 1) : '' ?>" class="autocomplete" table="{pre}areasample" /></td></tr>
                <tr><td><?= translate('AREA_NAME') ?>:</td><td><input type="text" name="row[name]" id="name" size="50" value="" /></td></tr>
                <tr><td><?= translate('AREA_HOST') ?>:</td><td><input type="text" name="row[host]" id="host" size="50" value="xxx.pengyougame.com:8513" /></td></tr>
                <tr><td><?= translate('AREA_OPENTIME') ?>:</td><td><input type="text" name="row[opentime]" id="opentime" size="25" value="<?= get_datetime(get_unixtime('day', 10)) ?>" class="datepicker" showtime="true" /></td></tr>

                <tr><td><?= translate('STATUS') ?>:</td><td>
                        <?php foreach ($statelist as $m => $n) { ?>
                            <input type="radio" name="row[state]" value="<?= $m ?>" id="s<?= $m ?>" <?= checkchecked('hide', $m) ?> /><label for="s<?= $m ?>"><?= $n ?></label> &nbsp;
                        <?php } ?>
                    </td></tr>
                <tr><td><?= translate('FLAG') ?>:</td><td>
                        <?php foreach ($flaglist as $m => $n) { ?>
                            <input type="radio" name="row[flag]" value="<?= $m ?>" id="s<?= $m ?>" <?= checkchecked('hide', $m) ?> /><label for="s<?= $m ?>"><?= $n ?></label> &nbsp;
                        <?php } ?>
                    </td></tr>
                <tr><td></td><td><input type="submit" value="<?= translate('SUBMIT') ?>" id="submit"/> <input type="reset" value="<?= translate('RESET') ?>" id="reset"/></td></tr>
            </table>
        </form>
        <script type="text/javascript">
            $(function() {
                $("#id").change(function() {
                    var num = $("#id").val().match(/\d+/g);
                    if (num && !isNaN(num)) {
                        $("#weigh").val(num);
                        $("#name").val(num + "区 ");
                        $("#url").val("http://" + num + ".<?= $_SERVER['SERVER_NAME'] ?>/api/");
                        $("#host").val(num + ".<?= $_SERVER['SERVER_NAME'] ?>:<?= $lastarea ? $lastarea['hostarr'][1] + 10 : '' ?>");
                    }
                });
                $("#id").change();
            });
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                $("#id").formValidator({empty: false, onshow: '<?= translate('C_ONLY_ONE') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#father_id").formValidator({empty: true, onshow: '<?= translate('AREA_FORM_INPUT_FATHER_ID') ?>'});
                $("#name").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#players").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#weigh").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#odds").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#version").formValidator({empty: true, onshow: '<?= translate('AREA_FORM_INPUT_VERSION') ?>'});
                $("#url").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#host").formValidator({empty: false, onshow: '<?= translate('AREA_FORM_INPUT_HOST') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#opentime").formValidator({empty: false, onshow: '<?= translate('AREA_FORM_INPUT_OPENTIME') ?>'}).regexValidator({regexp: "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$", onerror: '<?= translate('C_INVALID_TIME') ?>'});
            });
        </script>
    </body>
</html>